package com.ruoyi.oauth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oauth.domain.OauthClient;
import com.ruoyi.oauth.service.IOauthClientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端Controller
 * 
 * @author ruoyi
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/oauth/client")
public class OauthClientController extends BaseController
{
    @Autowired
    private IOauthClientService oauthClientService;

    /**
     * 查询客户端列表
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:list')")
    @GetMapping("/list")
    public TableDataInfo list(OauthClient oauthClient)
    {
        startPage();
        List<OauthClient> list = oauthClientService.selectOauthClientList(oauthClient);
        return getDataTable(list);
    }

    /**
     * 导出客户端列表
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:export')")
    @Log(title = "客户端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OauthClient oauthClient)
    {
        List<OauthClient> list = oauthClientService.selectOauthClientList(oauthClient);
        ExcelUtil<OauthClient> util = new ExcelUtil<OauthClient>(OauthClient.class);
        util.exportExcel(response, list, "客户端数据");
    }

    /**
     * 获取客户端详细信息
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:query')")
    @GetMapping(value = "/{clientId}")
    public AjaxResult getInfo(@PathVariable("clientId") String clientId)
    {
        return success(oauthClientService.selectOauthClientByClientId(clientId));
    }

    /**
     * 新增客户端
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:add')")
    @Log(title = "客户端", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OauthClient oauthClient)
    {
        return toAjax(oauthClientService.insertOauthClient(oauthClient));
    }

    /**
     * 修改客户端
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:edit')")
    @Log(title = "客户端", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OauthClient oauthClient)
    {
        return toAjax(oauthClientService.updateOauthClient(oauthClient));
    }

    /**
     * 删除客户端
     */
    @PreAuthorize("@ss.hasPermi('oauth:client:remove')")
    @Log(title = "客户端", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clientIds}")
    public AjaxResult remove(@PathVariable String[] clientIds)
    {
        return toAjax(oauthClientService.deleteOauthClientByClientIds(clientIds));
    }
}
